home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / mac / DirectX SDK / DXSDK / samples / Multimedia / Direct3D / BumpMapping / BumpLens / BumpLens.cpp next >
C/C++ Source or Header  |  2001-10-31  |  18KB  |  496 lines

  1. //-----------------------------------------------------------------------------
  2. // File: BumpLens.cpp
  3. //
  4. // Desc: Code to simulate a magnifying glass using bumpmapping.
  5. //
  6. // Note: Based on a sample from the Matrox web site
  7. //
  8. // Copyright (c) 2000-2001 Microsoft Corporation. All rights reserved.
  9. //-----------------------------------------------------------------------------
  10. #define STRICT
  11. #include <tchar.h>
  12. #include <math.h>
  13. #include <stdio.h>
  14. #include "D3DX8.h"
  15. #include "D3DApp.h"
  16. #include "D3DFont.h"
  17. #include "D3DUtil.h"
  18. #include "DXUtil.h"
  19. #include "resource.h"
  20.  
  21.  
  22.  
  23.  
  24. //-----------------------------------------------------------------------------
  25. // Function prototypes and global (or static) variables
  26. //-----------------------------------------------------------------------------
  27. inline DWORD F2DW( FLOAT f ) { return *((DWORD*)&f); }
  28.  
  29. struct BUMPVERTEX          // Vertex type used for bumpmap lens effect
  30. {
  31.     D3DXVECTOR3 p;
  32.     FLOAT       tu1, tv1;
  33.     FLOAT       tu2, tv2;
  34. };
  35.  
  36. struct BACKGROUNDVERTEX    // Vertex type used for rendering background
  37. {
  38.     D3DXVECTOR4 p;
  39.     DWORD       color;
  40.     FLOAT       tu, tv;
  41. };
  42.  
  43. #define D3DFVF_BUMPVERTEX       (D3DFVF_XYZ|D3DFVF_TEX2)
  44. #define D3DFVF_BACKGROUNDVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1)
  45.  
  46.  
  47.  
  48.  
  49. //-----------------------------------------------------------------------------
  50. // Name: class CMyD3DApplication
  51. // Desc: Application class. The base class (CD3DApplication) provides the 
  52. //       generic functionality needed in all Direct3D samples. CMyD3DApplication 
  53. //       adds functionality specific to this sample program.
  54. //-----------------------------------------------------------------------------
  55. class CMyD3DApplication : public CD3DApplication
  56. {
  57.     CD3DFont*               m_pFont;
  58.  
  59.     LPDIRECT3DVERTEXBUFFER8 m_pBackgroundVB;
  60.     LPDIRECT3DVERTEXBUFFER8 m_pLensVB;
  61.  
  62.     FLOAT                   m_fLensX;
  63.     FLOAT                   m_fLensY;
  64.  
  65.     LPDIRECT3DTEXTURE8      m_pBumpMapTexture;
  66.     LPDIRECT3DTEXTURE8      m_pBackgroundTexture;
  67.  
  68.     BOOL                    m_bDeviceValidationFailed;
  69.  
  70.     HRESULT CreateBumpMap( UINT iWidth, UINT iHeight );
  71.     HRESULT ConfirmDevice( D3DCAPS8*, DWORD, D3DFORMAT );
  72.  
  73. protected:
  74.     HRESULT OneTimeSceneInit();
  75.     HRESULT InitDeviceObjects();
  76.     HRESULT RestoreDeviceObjects();
  77.     HRESULT InvalidateDeviceObjects();
  78.     HRESULT DeleteDeviceObjects();
  79.     HRESULT Render();
  80.     HRESULT FrameMove();
  81.     HRESULT FinalCleanup();
  82.  
  83. public:
  84.     CMyD3DApplication();
  85. };
  86.  
  87.  
  88.  
  89.  
  90. //-----------------------------------------------------------------------------
  91. // Name: WinMain()
  92. // Desc: Entry point to the program. Initializes everything, and goes into a
  93. //       message-processing loop. Idle time is used to render the scene.
  94. //-----------------------------------------------------------------------------
  95. INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
  96. {
  97.     CMyD3DApplication d3dApp;
  98.  
  99.     if( FAILED( d3dApp.Create( hInst ) ) )
  100.         return 0;
  101.  
  102.     return d3dApp.Run();
  103. }
  104.  
  105.  
  106.  
  107.  
  108. //-----------------------------------------------------------------------------
  109. // Name: CMyD3DApplication()
  110. // Desc: Application constructor. Sets attributes for the app.
  111. //-----------------------------------------------------------------------------
  112. CMyD3DApplication::CMyD3DApplication()
  113. {
  114.     m_strWindowTitle     = _T("BumpLens: Lens Effect Using BumpMapping");
  115.     m_bUseDepthBuffer    = FALSE;
  116.  
  117.     m_pFont              = new CD3DFont( _T("Arial"), 12, D3DFONT_BOLD );
  118.  
  119.     m_pBumpMapTexture    = NULL;
  120.     m_pBackgroundTexture = NULL;
  121.  
  122.     m_pBackgroundVB      = NULL;
  123.     m_pLensVB            = NULL;
  124.     m_bDeviceValidationFailed = FALSE;
  125. }
  126.  
  127.  
  128.  
  129.  
  130. //-----------------------------------------------------------------------------
  131. // Name: OneTimeSceneInit()
  132. // Desc: Called during initial app startup, this function performs all the
  133. //       permanent initialization.
  134. //-----------------------------------------------------------------------------
  135. HRESULT CMyD3DApplication::OneTimeSceneInit()
  136. {
  137.     return S_OK;
  138. }
  139.  
  140.  
  141.  
  142.  
  143. //-----------------------------------------------------------------------------
  144. // Name: FrameMove()
  145. // Desc: Called once per frame, the call is the entry point for animating
  146. //       the scene.
  147. //-----------------------------------------------------------------------------
  148. HRESULT CMyD3DApplication::FrameMove()
  149. {
  150.     // Get a triangle wave between -1 and 1
  151.     m_fLensX = 2 * fabsf( 2 * ( (m_fTime/2) - floorf(m_fTime/2) ) - 1 ) - 1;
  152.  
  153.     // Get a regulated sine wave between -1 and 1
  154.     m_fLensY = 2 * fabsf( sinf( m_fTime ) ) - 1;
  155.  
  156.     return S_OK;
  157. }
  158.  
  159.  
  160.  
  161.  
  162. //-----------------------------------------------------------------------------
  163. // Name: Render()
  164. // Desc: Called once per frame, the call is the entry point for 3d
  165. //       rendering. This function sets up render states, clears the
  166. //       viewport, and renders the scene.
  167. //-----------------------------------------------------------------------------
  168. HRESULT CMyD3DApplication::Render()
  169. {
  170.     // Begin the scene
  171.     if( FAILED( m_pd3dDevice->BeginScene() ) )
  172.         return S_OK;
  173.  
  174.     // Render the background
  175.     m_pd3dDevice->SetTexture( 0, m_pBackgroundTexture );
  176.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  177.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
  178.     m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_DISABLE );
  179.  
  180.     m_pd3dDevice->SetVertexShader( D3DFVF_BACKGROUNDVERTEX );
  181.     m_pd3dDevice->SetStreamSource( 0, m_pBackgroundVB, sizeof(BACKGROUNDVERTEX) );
  182.     m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
  183.  
  184.     // Render the lens
  185.     m_pd3dDevice->SetTexture( 0, m_pBumpMapTexture );
  186.     m_pd3dDevice->SetTexture( 1, m_pBackgroundTexture );
  187.  
  188.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_BUMPENVMAP );
  189.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  190.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_CURRENT );
  191.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
  192.  
  193.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_BUMPENVMAT00,   F2DW(0.2f) );
  194.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_BUMPENVMAT01,   F2DW(0.0f) );
  195.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_BUMPENVMAT10,   F2DW(0.0f) );
  196.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_BUMPENVMAT11,   F2DW(0.2f) );
  197.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_BUMPENVLSCALE,  F2DW(1.0f) );
  198.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_BUMPENVLOFFSET, F2DW(0.0f) );
  199.  
  200.     m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
  201.     m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  202.     m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
  203.     m_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
  204.  
  205.     // Generate texture coords depending on objects camera space position
  206.     D3DXMATRIX mat;
  207.     mat._11 = 0.5f; mat._12 = 0.0f;
  208.     mat._21 = 0.0f; mat._22 =-0.5f;
  209.     mat._31 = 0.0f; mat._32 = 0.0f;
  210.     mat._41 = 0.5f; mat._42 = 0.5f;
  211.  
  212.     // Scale-by-z here
  213.     D3DXMATRIX matView, matProj;
  214.     m_pd3dDevice->GetTransform( D3DTS_VIEW,       &matView );
  215.     m_pd3dDevice->GetTransform( D3DTS_PROJECTION, &matProj );
  216.     D3DXVECTOR3 vEyePt( matView._41, matView._42, matView._43 );
  217.     FLOAT       z = D3DXVec3Length( &vEyePt );
  218.     mat._11 *= ( matProj._11 / ( matProj._33 * z + matProj._34 ) );
  219.     mat._22 *= ( matProj._22 / ( matProj._33 * z + matProj._34 ) );
  220.  
  221.     m_pd3dDevice->SetTransform( D3DTS_TEXTURE1, &mat );
  222.     m_pd3dDevice->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
  223.     m_pd3dDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION | 1);
  224.  
  225.     // Position the lens
  226.     D3DXMATRIX matWorld;
  227.     D3DXMatrixTranslation( &matWorld, 0.7f * (1000.0f-256.0f)*m_fLensX,
  228.                                       0.7f * (1000.0f-256.0f)*m_fLensY,
  229.                                       0.0f );
  230.     m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
  231.  
  232.     m_pd3dDevice->SetVertexShader( D3DFVF_BUMPVERTEX );
  233.     m_pd3dDevice->SetStreamSource( 0, m_pLensVB, sizeof(BUMPVERTEX) );
  234.  
  235.     // Verify that the texture operations are possible on the device
  236.     DWORD dwNumPasses;
  237.     if( FAILED( m_pd3dDevice->ValidateDevice( &dwNumPasses ) ) )
  238.     {
  239.         // The right thing to do when device validation fails is to try
  240.         // a different rendering technique.  This sample just warns the user.
  241.         m_bDeviceValidationFailed = TRUE;
  242.     }
  243.  
  244.     // Render the lens
  245.     m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
  246.  
  247.     // Output statistics
  248.     m_pFont->DrawText( 2,  0, D3DCOLOR_ARGB(255,255,255,0), m_strFrameStats );
  249.     m_pFont->DrawText( 2, 20, D3DCOLOR_ARGB(255,255,255,0), m_strDeviceStats );
  250.  
  251.     if( m_bDeviceValidationFailed )
  252.     {
  253.         m_pFont->DrawText( 2, 40, D3DCOLOR_ARGB(255,255,0,0), 
  254.             _T("Warning: Device validation failed.  Rendering may not look right.") );
  255.     }
  256.  
  257.     // End the scene.
  258.     m_pd3dDevice->EndScene();
  259.  
  260.     return S_OK;
  261. }
  262.  
  263.  
  264.  
  265.  
  266. //-----------------------------------------------------------------------------
  267. // Name: CreateBumpmap()
  268. // Desc: Create a bump map texture and fill its content to BUMPDUDV format
  269. //-----------------------------------------------------------------------------
  270. HRESULT CMyD3DApplication::CreateBumpMap( UINT iWidth, UINT iHeight )
  271. {
  272.     // Create the bumpmap's surface and texture objects
  273.     if( FAILED( m_pd3dDevice->CreateTexture( iWidth, iHeight, 1, 0, 
  274.         D3DFMT_V8U8, D3DPOOL_MANAGED, &m_pBumpMapTexture ) ) )
  275.     {
  276.         return E_FAIL;
  277.     }
  278.  
  279.     // Fill the bumpmap texels to simulate a lens
  280.     D3DLOCKED_RECT d3dlr;
  281.     m_pBumpMapTexture->LockRect( 0, &d3dlr, 0, 0 );
  282.     DWORD dwDstPitch = (DWORD)d3dlr.Pitch;
  283.     BYTE* pDst       = (BYTE*)d3dlr.pBits;
  284.     UINT  mid        = iWidth/2;
  285.  
  286.     for( DWORD y0 = 0; y0 < iHeight; y0++ )
  287.     {
  288.         CHAR* pDst = (CHAR*)d3dlr.pBits + y0*d3dlr.Pitch;
  289.  
  290.         for( DWORD x0 = 0; x0 < iWidth; x0++ )
  291.         {
  292.             DWORD x1 = ( (x0==iWidth-1)  ? x0 : x0+1 );
  293.             DWORD y1 = ( (x0==iHeight-1) ? y0 : y0+1 );
  294.  
  295.             FLOAT fDistSq00 = (FLOAT)( (x0-mid)*(x0-mid) + (y0-mid)*(y0-mid) );
  296.             FLOAT fDistSq01 = (FLOAT)( (x1-mid)*(x1-mid) + (y0-mid)*(y0-mid) );
  297.             FLOAT fDistSq10 = (FLOAT)( (x0-mid)*(x0-mid) + (y1-mid)*(y1-mid) );
  298.  
  299.             FLOAT v00 = ( fDistSq00 > (mid*mid) ) ? 0.0f : sqrtf( (mid*mid) - fDistSq00 );
  300.             FLOAT v01 = ( fDistSq01 > (mid*mid) ) ? 0.0f : sqrtf( (mid*mid) - fDistSq01 );
  301.             FLOAT v10 = ( fDistSq10 > (mid*mid) ) ? 0.0f : sqrtf( (mid*mid) - fDistSq10 );
  302.  
  303.             FLOAT iDu = (128/D3DX_PI)*atanf(v00-v01); // The delta-u bump value
  304.             FLOAT iDv = (128/D3DX_PI)*atanf(v00-v10); // The delta-v bump value
  305.  
  306.             *pDst++ = (CHAR)(iDu);
  307.             *pDst++ = (CHAR)(iDv);
  308.         }
  309.     }
  310.  
  311.     m_pBumpMapTexture->UnlockRect(0);
  312.  
  313.     return S_OK;
  314. }
  315.  
  316.  
  317.  
  318.  
  319. //-----------------------------------------------------------------------------
  320. // Name: InitDeviceObjects()
  321. // Desc: Initialize scene objects
  322. //-----------------------------------------------------------------------------
  323. HRESULT CMyD3DApplication::InitDeviceObjects()
  324. {
  325.     m_pFont->InitDeviceObjects( m_pd3dDevice );
  326.  
  327.     // Load the texture for the background image
  328.     if( FAILED( D3DUtil_CreateTexture( m_pd3dDevice, _T("Lake.bmp"),
  329.                                        &m_pBackgroundTexture ) ) )
  330.         return E_FAIL;
  331.  
  332.     // Create the bump map texture
  333.     if( FAILED( CreateBumpMap( 256, 256 ) ) )
  334.        return E_FAIL;
  335.  
  336.     // Create a square for rendering the background
  337.     if( FAILED( m_pd3dDevice->CreateVertexBuffer( 4*sizeof(BACKGROUNDVERTEX),
  338.                                                   D3DUSAGE_WRITEONLY, D3DFVF_BACKGROUNDVERTEX,
  339.                                                   D3DPOOL_MANAGED, &m_pBackgroundVB ) ) )
  340.         return E_FAIL;
  341.  
  342.     // Create a square for rendering the lens
  343.     if( FAILED( m_pd3dDevice->CreateVertexBuffer( 4*sizeof(BUMPVERTEX),
  344.                                                   D3DUSAGE_WRITEONLY, D3DFVF_BUMPVERTEX,
  345.                                                   D3DPOOL_MANAGED, &m_pLensVB ) ) )
  346.         return E_FAIL;
  347.  
  348.     BUMPVERTEX* vLens;
  349.     m_pLensVB->Lock( 0, 0, (BYTE**)&vLens, 0 );
  350.     vLens[0].p = D3DXVECTOR3(-256.0f,-256.0f, 0.0f );
  351.     vLens[1].p = D3DXVECTOR3(-256.0f, 256.0f, 0.0f );
  352.     vLens[2].p = D3DXVECTOR3( 256.0f,-256.0f, 0.0f );
  353.     vLens[3].p = D3DXVECTOR3( 256.0f, 256.0f, 0.0f );
  354.     vLens[0].tu1 = 0.0f; vLens[0].tv1 = 1.0f;
  355.     vLens[1].tu1 = 0.0f; vLens[1].tv1 = 0.0f;
  356.     vLens[2].tu1 = 1.0f; vLens[2].tv1 = 1.0f;
  357.     vLens[3].tu1 = 1.0f; vLens[3].tv1 = 0.0f;
  358.     m_pLensVB->Unlock();
  359.  
  360.     m_bDeviceValidationFailed = FALSE;
  361.  
  362.     return S_OK;
  363. }
  364.  
  365.  
  366.  
  367.  
  368. //-----------------------------------------------------------------------------
  369. // Name: RestoreDeviceObjects()
  370. // Desc: Initialize scene objects
  371. //-----------------------------------------------------------------------------
  372. HRESULT CMyD3DApplication::RestoreDeviceObjects()
  373. {
  374.     m_pFont->RestoreDeviceObjects();
  375.  
  376.     // Set the transform matrices
  377.     D3DXVECTOR3 vEyePt    = D3DXVECTOR3( 0.0f, 0.0f, -2001.0f );
  378.     D3DXVECTOR3 vLookatPt = D3DXVECTOR3( 0.0f, 0.0f,     0.0f );
  379.     D3DXVECTOR3 vUpVec    = D3DXVECTOR3( 0.0f, 1.0f,     0.0f );
  380.     D3DXMATRIX matWorld, matView, matProj;
  381.  
  382.     D3DXMatrixIdentity( &matWorld );
  383.     D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
  384.     FLOAT fAspect = m_d3dsdBackBuffer.Width / (FLOAT)m_d3dsdBackBuffer.Height;
  385.     D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, fAspect, 1.0f, 3000.0f );
  386.     m_pd3dDevice->SetTransform( D3DTS_WORLD,      &matWorld );
  387.     m_pd3dDevice->SetTransform( D3DTS_VIEW,       &matView );
  388.     m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
  389.  
  390.     // Set any appropiate state
  391.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
  392.     m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
  393.     m_pd3dDevice->SetTextureStageState( 1, D3DTSS_ADDRESSU,   D3DTADDRESS_CLAMP );
  394.     m_pd3dDevice->SetTextureStageState( 1, D3DTSS_ADDRESSV,   D3DTADDRESS_CLAMP );
  395.     m_pd3dDevice->SetTextureStageState( 1, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
  396.     m_pd3dDevice->SetTextureStageState( 1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
  397.     m_pd3dDevice->SetTextureStageState( 1, D3DTSS_MIPFILTER, D3DTEXF_NONE );
  398.  
  399.     // Size the background image
  400.     BACKGROUNDVERTEX* vBackground;
  401.     m_pBackgroundVB->Lock( 0, 0, (BYTE**)&vBackground, 0 );
  402.     for( UINT i=0; i<4; i ++ )
  403.     {
  404.         vBackground[i].p = D3DXVECTOR4( 0.0f, 0.0f, 0.9f, 1.0f );
  405.         vBackground[i].color = 0xffffffff;
  406.     }
  407.     vBackground[0].p.y = (FLOAT)m_d3dsdBackBuffer.Height;
  408.     vBackground[2].p.y = (FLOAT)m_d3dsdBackBuffer.Height;
  409.     vBackground[2].p.x = (FLOAT)m_d3dsdBackBuffer.Width;
  410.     vBackground[3].p.x = (FLOAT)m_d3dsdBackBuffer.Width;
  411.     vBackground[0].tu = 0.0f; vBackground[0].tv = 1.0f;
  412.     vBackground[1].tu = 0.0f; vBackground[1].tv = 0.0f;
  413.     vBackground[2].tu = 1.0f; vBackground[2].tv = 1.0f;
  414.     vBackground[3].tu = 1.0f; vBackground[3].tv = 0.0f;
  415.     m_pBackgroundVB->Unlock();
  416.  
  417.     return S_OK;
  418. }
  419.  
  420.  
  421.  
  422.  
  423. //-----------------------------------------------------------------------------
  424. // Name: InvalidateDeviceObjects()
  425. // Desc:
  426. //-----------------------------------------------------------------------------
  427. HRESULT CMyD3DApplication::InvalidateDeviceObjects()
  428. {
  429.     m_pFont->InvalidateDeviceObjects();
  430.     return S_OK;
  431. }
  432.  
  433.  
  434.  
  435.  
  436. //-----------------------------------------------------------------------------
  437. // Name: DeleteDeviceObjects()
  438. // Desc: Called when the app is exiting, or the device is being changed,
  439. //       this function deletes any device dependent objects.
  440. //-----------------------------------------------------------------------------
  441. HRESULT CMyD3DApplication::DeleteDeviceObjects()
  442. {
  443.     m_pFont->DeleteDeviceObjects();
  444.     SAFE_RELEASE( m_pBackgroundTexture );
  445.     SAFE_RELEASE( m_pBumpMapTexture );
  446.     SAFE_RELEASE( m_pBackgroundVB );
  447.     SAFE_RELEASE( m_pLensVB );
  448.  
  449.     return S_OK;
  450. }
  451.  
  452.  
  453.  
  454.  
  455. //-----------------------------------------------------------------------------
  456. // Name: FinalCleanup()
  457. // Desc: Called before the app exits, this function gives the app the chance
  458. //       to cleanup after itself.
  459. //-----------------------------------------------------------------------------
  460. HRESULT CMyD3DApplication::FinalCleanup()
  461. {
  462.     SAFE_DELETE( m_pFont );
  463.     return S_OK;
  464. }
  465.  
  466.  
  467.  
  468.  
  469. //-----------------------------------------------------------------------------
  470. // Name: ConfirmDevice()
  471. // Desc: Called during device intialization, this code checks the device
  472. //       for some minimum set of capabilities
  473. //-----------------------------------------------------------------------------
  474. HRESULT CMyD3DApplication::ConfirmDevice( D3DCAPS8* pCaps, DWORD dwBehavior,
  475.                                           D3DFORMAT Format )
  476. {
  477.     if( dwBehavior & D3DCREATE_PUREDEVICE )
  478.         return E_FAIL; // GetTransform doesn't work on PUREDEVICE
  479.  
  480.     // Device must be able to do bumpmapping
  481.     if( 0 == ( pCaps->TextureOpCaps & D3DTEXOPCAPS_BUMPENVMAP ) )
  482.         return E_FAIL;
  483.  
  484.     // Accept devices that can create D3DFMT_V8U8 textures
  485.     if( SUCCEEDED( m_pD3D->CheckDeviceFormat( pCaps->AdapterOrdinal,
  486.                                               pCaps->DeviceType, Format,
  487.                                               0, D3DRTYPE_TEXTURE,
  488.                                               D3DFMT_V8U8 ) ) )
  489.         return S_OK;
  490.  
  491.     return E_FAIL;
  492. }
  493.  
  494.  
  495.  
  496.